<?php if(count($listingAssets)){?>
<?php
	$i = 0;
	$firstItem = null; 
	$itemToShow = null;
	$itemIndex = 0;
	$itemsIndex = array();
	if(!isset($assetToShow))
	{
		$assetToShow = null;
	}
	foreach($listingAssets as $listingAsset){
		if($i == 0)
		{
			$firstItem = $listingAsset;
		}
		if($assetToShow && $listingAsset['ListingAsset']['id'] == $assetToShow)
		{
			$itemIndex = $i;
			$itemToShow = $listingAsset;
		}
		$itemsIndex[$i] = $listingAsset['ListingAsset']['id'];
		$i++;
	}
	if(!$itemToShow)
	{
		$itemToShow = $firstItem;
		$itemIndex = 0;
	} 
?>
<?php 
	$prevId = $nextId = null;
	$prevId = @$itemsIndex[$itemIndex - 1];
	$nextId = @$itemsIndex[$itemIndex + 1];
?>
<div class="gallery_layout">
	<div class="paginate gallery_paginate" style="">
		<?php 
			$nextText = __("Next >>");
			$prevText = __("<< Prev");
		?>
		<?php
			if(!is_null($prevId))
			{
				echo $html->link($prevText,am($this->params['pass'],am($this->params['named'],array("show"=>$prevId))));
			}else
			{
				echo $prevText;
			}
		?>
		<strong>
			<?php echo sprintf(__("%d  of %d"),$itemIndex+1,count($itemsIndex))?>
		</strong>
		<?php 
			if(!is_null($nextId))
			{
				echo $html->link($nextText,am($this->params['pass'],am($this->params['named'],array("show"=>$nextId))));
			}else
			{
				echo $nextText;
			}
		?>
    <?php if(cr("GeneralConfig.lightboxGallery")){?>
      <div class="unitExt" style="height:20px;cursor: pointer">
          <span class="image_add showlightbox" style="padding-bottom: 10px" title="<?php echo __("Gallery view")?>"></span>  
      </div>
     <?php } ?> 
	</div>
	<div class="selected_image_display">
			<div class="selected_image" style=""  id="selected_image">
				<?php echo $html->link($asset->preview($itemToShow['ListingAsset'], array('class'=>'', 'id'=>"main_asset_image",'thumb'=>array('width'=>400,'height'=>400,'crop'=>false))),am($this->params['pass'],am($this->params['named'],array("show"=>$nextId))),array("escape"=>false));?>
			</div>
		
	</div>

	<div class="uploader_info">
			<?php if(isset($listingGallery)){?>
			
			<div style="margin-bottom: 1px;margin-top: 1px;">
				<?php echo $html->link($html->image($itemToShow['ListingAsset']['poster']['avatar'],array('class'=>"profile_pic",'alt'=>sprintf(__("%s profile"),$itemToShow['ListingAsset']['poster']['display_name']),'thumb'=>array('crop'=>true,'width'=>40,'height'=>40))),$itemToShow['ListingAsset']['poster']['profile_url'],array("escape"=>false));?>
			</div>
			<div>
			<?php echo __("Uploaded By")?>
				<?php echo $html->link($itemToShow['ListingAsset']['poster']['display_name'],$itemToShow['ListingAsset']['poster']['profile_url']);?> 
			</div>
			<?php }else{ ?>
				<?php echo __("Uploaded In")?>
				<div style="margin-bottom: 1px;margin-top: 1px;">
					<?php echo $html->link($html->image($itemToShow['Listing']['image'],array('class'=>"profile_pic",'alt'=>$itemToShow['Listing']['title'],'thumb'=>array('crop'=>true,'width'=>40,'height'=>40))),$itemToShow['Listing']['viewUrl'],array("escape"=>false));?>
				</div>
			<div>
				<?php echo $html->link($itemToShow['Listing']['title'],$itemToShow['Listing']['viewUrl']);?> 
			</div>
			<?php } ?>	
			<div>
			<?php echo $time->timeAgoInWords($itemToShow['ListingAsset']['created'],array('shortString'=>true));?>
			<?php if($itemToShow['ListingAsset']['poster']['id'] == $session->read("Auth.User.id") && cr("ListingConfig.allow_asset_edit")){?>
				<?php echo " | ".$html->link(__("Delete"),array("action"=>"delete",$itemToShow['ListingAsset']['id']),array(),__("Are you sure you want to delete this image?"));?>
			<?php } ?>	 
			<?php //echo $report->link("ListingAsset",$assetData['ListingAsset']['id'],array('title'=>"Report"))?>
			</div>
		</div>
		<?php if(cr('GeneralConfig.allow_comment_on_gallery')){?>
		<br />
		<div class="images_comment_wrap">
			<?php echo $this->element("images_comment_block",array("assetData"=>$itemToShow))?>
		</div>
		<?php } ?>
</div>
<div style="padding-top:10px;padding-bottom:40px;">
	<?php 
$i = 0;
$columns = 3;
foreach($listingAssets as $listingAsset) 
{
	$listingAssetInfo = $listingAsset;
	$listingAsset = $listingAsset['ListingAsset'];
	
	if(strlen($listingAsset['name']) < 1)
		continue;
	if($i%$columns==0) echo "<div class='clr' ></div>"; ?>
	
 	<div class="galleryImage" style="float:left;padding-right:10px;padding-top:40px;">
 		<?php 
 			$url = am($this->params['pass'],$this->params['named'],array("show"=>$listingAsset['id']));
 			$imageHtml = $asset->preview($listingAsset, array('thumb'=>array('height'=>76,'width'=>100,'crop'=>true)));
 			echo $html->link($imageHtml,$url,array('escape'=>false)); ?>
	<div style="padding-top:5px">
			<?php if(isset($listingGallery)){?>
				<?php echo __("By")?> <?php echo $html->link($listingAsset['poster']['display_name'],$listingAsset['poster']['profile_url']);?>
			<?php }else{ ?>
					<?php echo __("In")?> <?php echo $html->link($listingAssetInfo['Listing']['title'],$listingAssetInfo['Listing']['viewUrl']);?>
			<?php } ?>	
	</div>
	</div>	
	<span class="clear"></span>
<?php $i++;
}
?>
<div class="clear"></div>
</div>
<div>
	<?php 
		$paginator->options(array('url'=>$this->getPagingUrl()));
	echo $paginator->numbers()?>
</div>
<script>
  $(document).ready(function() {
    var fn = function(){
    var height = $('#main_asset_image').height();
    if(height == 0)
    {
      return;
    }
    height = 450 -height;
    if(height > 1)
     {
       height = height/2;
       $('#selected_image').css("padding-top",height+'px');
     }
    }
    $('#main_asset_image').load(fn);
    setTimeout(fn,3000);
    <?php if(cr('GeneralConfig.allow_comment_on_gallery')){
        $javascript->link("/js/jquery.lightbox.min",false); 
        $html->css("/css/jquery.lightbox.css",null,array(),false);
     ?>
      var elems = [];
      var windowHeight = $(window).height();
      var windowWidth = $(window).width();
      var imgHeight = 0.8*windowHeight;
      imgHeight = imgHeight.toFixed(2);
      var imgWidth = 0.8*windowWidth;
      imgWidth = imgWidth.toFixed();
      imgHeight = 800//imgHeight > 800 ? 800 : imgHeight;
      imgWidth = 500;//imgWidth > 800 ? 800 : imgWidth;
  $('.galleryImage').each(function(){
    var obj = $(this);
    var anchor = obj.children("a");
    var pageUrl = anchor.attr("href");
    var url = anchor.children("img").attr("src");
    url = url.replace('/crop/', '/');
    url = url.replace(/\d+x\d+/,imgWidth+'x'+imgHeight);
    anchor.attr("href",url);
    $(anchor).data("caption",'<div><a href="'+pageUrl+'"><?php echo __("Go to page of this image")?></a></div>');
    elems.push(anchor[0]);
  });
  if(elems.length)
   {
     $(elems).lightBox({fixedNavigation:false})
      $('.showlightbox').click(function(e){
        e.preventDefault();
        $(elems[0]).trigger('click');
    })
  }
    <?php  }?>    
  })
</script>
<?php }else{?>
	<h4><?php echo __("No image has been uploaded yet for this listing yet.")?></h4>
<?php } ?>	
